//
//  ClassViewController.m
//  WY_Milk
//
//  Created by wangyang on 2020/2/3.
//  Copyright © 2020 wangyang. All rights reserved.
//

#import "ClassViewController.h"
#import "ClassViewCell.h"
#import "DetailsVc.h"

@interface ClassViewController ()<UITableViewDelegate,UITableViewDataSource,ClassViewCellDele>

@property (nonatomic,strong) UITableView     *WyHomeTableView;
@property (nonatomic,strong) NSMutableArray     *WyArray;

@end

@implementation ClassViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.navigationItem.title = _navStr;
    self.view.backgroundColor = WyWhiteColor;
    [self WyHomeTableView];
    

}


- (NSMutableArray *)WyArray{
    
    
    if (!_WyArray) {
        _WyArray = [[NSMutableArray alloc] init];
        [_WyArray removeAllObjects];
        
        if (_type == 0) {
            _WyArray = [NSJSONSerialization JSONObjectWithData:[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Home" ofType:@"json"]] options:NSJSONReadingMutableContainers error:nil][@"线装古籍"];
        }
        
       else if (_type == 1)
       {
            _WyArray = [NSJSONSerialization JSONObjectWithData:[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Home" ofType:@"json"]] options:NSJSONReadingMutableContainers error:nil][@"人物传记"];
           
       }
        else if (_type == 2)
        {
             _WyArray = [NSJSONSerialization JSONObjectWithData:[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Home" ofType:@"json"]] options:NSJSONReadingMutableContainers error:nil][@"名人墨迹"];
            
        }
        else if (_type == 3)
        {
             _WyArray = [NSJSONSerialization JSONObjectWithData:[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Home" ofType:@"json"]] options:NSJSONReadingMutableContainers error:nil][@"新书频道"];
            
        }
        
        else  if (_type == 4) {
             _WyArray = [NSJSONSerialization JSONObjectWithData:[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Home" ofType:@"json"]] options:NSJSONReadingMutableContainers error:nil][@"好书排行"];
        }
        
        
        
        NSLog(@"%@",_WyArray);
        
        
        
        
    }
    return _WyArray;
    
}

-(UITableView *)WyHomeTableView

{
    
    if (!_WyHomeTableView) {
        
        
        _WyHomeTableView = [[UITableView alloc]init];
           _WyHomeTableView.delegate = self;
           _WyHomeTableView.dataSource = self;
           _WyHomeTableView.showsVerticalScrollIndicator = YES;
           _WyHomeTableView.backgroundColor = [UIColor clearColor];
           _WyHomeTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
           [self.view addSubview:_WyHomeTableView];
           [_WyHomeTableView mas_makeConstraints:^(MASConstraintMaker *make) {
               make.left.right.top.bottom.mas_offset(0);
           }];
           [_WyHomeTableView registerClass:[ClassViewCell class] forCellReuseIdentifier:@"Cell"];
        if (@available(iOS 11.0, *)) {

        _WyHomeTableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        }
    }
    return _WyHomeTableView;
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;

{
    return self.WyArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{
    static NSString *CellId = @"Cell";
    
    ClassViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellId];
    
    if (!cell) {
        cell = [[ClassViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellId];
    }
    cell.backgroundColor = [UIColor clearColor];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.delegate = self;
    cell.IndexPath = indexPath;
    
    cell.PicImg.image = [UIImage imageNamed:self.WyArray[indexPath.row][@"img"]];
    cell.NameLabe.text = self.WyArray[indexPath.row][@"name"];
    cell.UserNameLabe.text = self.WyArray[indexPath.row][@"UserName"];
    cell.MoneyLabe.text = self.WyArray[indexPath.row][@"money"];
    cell.ScoreLabe.text = self.WyArray[indexPath.row][@"Score"];
    cell.DiscountLabe.text = self.WyArray[indexPath.row][@"Promotion"];
    
    return cell;
}




-(void)WyBtnClickIndexPath:(NSIndexPath *)IndexPath

{
    DetailsVc *Details = [[DetailsVc alloc]init];
    Details.DetailsVcDicy = self.WyArray[IndexPath.row];
    [self.navigationController pushViewController:Details animated:YES];
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return BiLiWidth(115+20);
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
